using Abp.AspNetCore.Mvc.Controllers;
using Batman.Jianbei.Forum.Factories;
using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using Batman.Cms.Core.Models.Mvc;
using Batman.Core.Utils;
using Batman.Jianbei.Forum.Areas.Forum.Inputs;
using Batman.Jianbei.Forum.Core.Domains.Socials;
using Batman.Jianbei.Forum.Repositories.Mongo;
using Microsoft.AspNetCore.Authorization;
using MongoDB.Driver;

namespace Batman.Jianbei.Forum.Areas.Forum
{
    /// <summary>
    /// 访问统计
    /// </summary>
    [Area("Forum")]
    public class AccessController : AbpController
    {
        public AccessRepository AccessRepository { get; set; }

        /// <summary>
        /// 访问记录（写入）
        /// </summary>
        /// <returns></returns>
        [Authorize]
        public IActionResult Record(List<AccessInput> models)
        {
            var wid = User.GetWxUserId();

            var records = models.Select(t => new Access(t.PostId, wid, t.AccessAt)).ToList();

            AccessRepository.Insert(records);

            return Json(new ResponseBase());
        }
    }
}